package 临时工具.csvFile;

import java.io.File;
import java.util.Vector;


public class ReadFileName {

    //存储遍历获取的所有文件名
    private Vector<String> filelist = new Vector<String>();


    //遍历指定路径下的所有文件
    //以ArrayList存储于filelist中
    private  void RefreshFileList(String strpath) {
        File dir = new File(strpath);
        File[] files = dir.listFiles();


        if (files == null)
            return;
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                RefreshFileList(files[i].getAbsolutePath());
            } else {
                //String strFileName = files[i].getAbsolutePath().toLowerCase();
                filelist.add(files[i].getAbsolutePath());
            }
        }
    }

    //过滤当前目录下的指定后缀名的文件
    //返回Vector
    public  Vector<String> FileNameOftype(String strpath2,String filetype){
        String strfilename=new String();
        Vector<String> filelistofjava= new Vector<String>();

        //读取指定路径下的所有文件
        RefreshFileList(strpath2);

        for (int i = 0; i < filelist.size(); i++) {
            strfilename=filelist.get(i).toString();
            strfilename=strfilename.substring(strfilename.length()-4, strfilename.length());

            if (strfilename.equals(filetype)) {
                filelistofjava.add(filelist.get(i));
            }
        }
        return filelistofjava;
    }

}
